#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<math.h>
using namespace std;
const long long MAXN=2333;
long long arr[MAXN];
long long n,k;
long long point;
long long ans;
long long summ;

long long dfs(int);
void init()
{
	cin>>n>>k;
	for(int i=0;i<n;++i)
	{
		cin>>arr[i];
	}
	point =0;
	ans=0;
	summ=n;
	dfs(k);
	cout<<ans<<endl;
}
long long dfs(int kk)
{
	
	cout<<kk<<endl;
	summ--;if(kk==0)return arr[point++];
	long long aa= summ? dfs(kk-1):arr[point++];
	long long bb= summ? dfs(kk-1):arr[point++];
	
	cout<<aa<<ends<<bb<<endl;
	ans+=abs(aa-bb);
	return max(aa,bb);
	
}

int main()
{
	cin.sync_with_stdio(false);
	init();
	
	return 0;
}
